#!/bin/bash
# This is run from echoirlp-status when tbd updates the hosts file 
# and keeps a list of all echolink hosts that appear in a hosts-all file.

[ -z "$ECHO_SCRIPT" ] && ECHO_SCRIPT=/home/EchoIRLP/scripts
   source $ECHO_SCRIPT/echo_common


if [ -f "$ECHO_TBD_DATA/hosts-all" ] ; then
	sort -u -n -t# -k 2 "$ECHO_TBD_DATA/hosts" "$ECHO_TBD_DATA/hosts-all" \
		> "$ECHO_TBD_DATA/hosts-all.temp"
	mv -f "$ECHO_TBD_DATA/hosts-all.temp" "$ECHO_TBD_DATA/hosts-all"
else
	cp -p "$ECHO_TBD_DATA/hosts" "$ECHO_TBD_DATA/hosts-all"
fi
cat "$ECHO_TBD_DATA/hosts-all" | sed s/\ //g|sed s/#//g | \
      gawk -F'\t' '{ print $2"\t-\t"$3"\t"$1 }' > "$ECHOLINUX/echo_hosts.temp"
mv -f "$ECHOLINUX/echo_hosts.temp" "$ECHOLINUX/echo_hosts"

if [ -f "$ECHO_SCRIPT/echo_upload" ] ; then "$ECHO_SCRIPT/echo_upload" ; fi

exit
